//package com.example.concurrentprogramming8016.thread.cas;
//
//
//import sun.misc.Unsafe;
//
//import java.lang.reflect.Field;
//
///**
// * @author liyanhao
// * @Date 2023-01-04 1:21
// */
//public class UnsafeFactory {
//    //获取unsafe对象
//    public static Unsafe getUnsafe() throws NoSuchFieldException {
//        try {
//            Field theUnsafe = Unsafe.class.getDeclaredField("theUnsafe");
//            theUnsafe.setAccessible(true);
//            return (Unsafe) theUnsafe.get(null);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        return null;
//    }
//
//    //获取字段的偏移量
//    public static long getFieldOffset(Unsafe unsafe, Class clazz, String fieldName) {
//        try {
//            return unsafe.objectFieldOffset(clazz.getDeclaredField(fieldName));
//        } catch (NoSuchFieldException e) {
//            throw new RuntimeException(e);
//        }
//
//    }
//}
